package com.km.demo.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.km.demo.entities.Book;
import com.km.demo.jpa.BookJpa;
import com.km.demo.service.BookService;
import com.km.demo.utils.JsonResult;

@RestController
public class DemoController {
	@Autowired
	BookJpa bookJpa;
	@Autowired
	private BookService bookService;
	@GetMapping(value="/getAll")
	public List<Book> getAll(){
		return bookJpa.findAll();
	}
	@GetMapping(value="/getOne/{id}")
	public Book getById(@PathVariable("id") Integer id){
		return bookJpa.findOne(id);
	}
	@PostMapping(value="/add")
	public Book add(Book book){
		bookJpa.save(book);
		return book;
	}
	@GetMapping("/queryPrice/{price}")
	public JsonResult queryPrice(@PathVariable("price") double price){
		return bookService.putInfo(price);
	}
}
